package com.hzit.controller;

import com.hzit.dto.SpecificationDTO;
import com.hzit.entity.R;
import com.hzit.entity.Spec;
import com.hzit.service.ISpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.persistence.GeneratedValue;
import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@RestController
@RequestMapping("/specification")
public class SpecificationController {
	@Autowired
	private ISpecificationService specificationService;

	//1. 列表规格
	@GetMapping("/list")
	public R list(){
		List<SpecificationDTO> specificationDTOList = specificationService.findAll();
		return R.ok().data("list",specificationDTOList);
	}
	//2. 规格id查询规格及规格选项
	@GetMapping("findById")
	public R findById(Integer id){
		Spec spec = specificationService.findById(id);
		return R.ok().data("spec",spec);
	}
	//3. 添加规格
	@PostMapping("/add")
	public R add(@RequestBody Spec spec){
		specificationService.insert(spec);
		return R.ok().message("添加规格成功!");
	}
	//4. 修改规格
	@PostMapping("/update")
	public R update(@RequestBody Spec spec){
		specificationService.update(spec);
		return R.ok().message("修改规格成功！");
	}
	//5. 删除规格
	@GetMapping("/delete")
	public R delete(Integer id){
		specificationService.delete(id);
		return R.ok().message("删除规格成功！");
	}
}
